package com.keyancompany.zhongbaopingtai.activity;

import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.Toolbar;

import com.keyancompany.zhongbaopingtai.R;
import com.keyancompany.zhongbaopingtai.adapter.IFragmentPagerAdapter;
import com.keyancompany.zhongbaopingtai.fragment.ComplainingFragment;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.BindString;

/**
 * 我的申诉
 */
public class ComplaintActivity extends BaseActivity {
    @BindString(R.string.my_complaint_text)
    String title;
    @Bind(R.id.toolbar)
    Toolbar toolbar;
    @Bind(R.id.tabLayout)
    TabLayout tabLayout;
    @Bind(R.id.complaint_viewpager)
    ViewPager complaintViewpager;

    @Override
    protected int getContentViewId() {
        return R.layout.activity_complaint;
    }

    @Override
    protected int getMenuId() {
        return 0;
    }

    @Override
    protected void initToolBar() {
        initToolBar(toolbar, title);
    }

    @Override
    protected void setUpViews() {

        List<Fragment> tcf = new ArrayList<>();
        tcf.add(ComplainingFragment.newInstance(1));
        tcf.add(ComplainingFragment.newInstance(0));
        IFragmentPagerAdapter pagerAdapter = new IFragmentPagerAdapter(getSupportFragmentManager(), tcf);
        pagerAdapter.setTitles(new String[]{"我发布的", "我参与的"});
        complaintViewpager.setAdapter(pagerAdapter);
        tabLayout.setupWithViewPager(complaintViewpager);
        tabLayout.setTabMode(TabLayout.MODE_FIXED);
    }

    /**
     * Created by Administrator on 2015/7/30.
     */
    public class SimpleFragmentPagerAdapter extends FragmentPagerAdapter {

        final int PAGE_COUNT = 2;
        private String tabTitles[] = new String[]{"未受理", "已受理"};

        public SimpleFragmentPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            return ComplainingFragment.newInstance(position + 1);
        }

        @Override
        public int getCount() {
            return PAGE_COUNT;
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return tabTitles[position];
        }
    }


}
